#include<bits/stdc++.h>
using namespace std;
int n,m;
void solve(int n,int m) {
    if (n==1) {
        for (int i=1;i<=m;i++) {
            printf("%d %d\n",1,i);
        }
        return;
    }
    if (m==1) {
        for (int i=1;i<=n;i++) {
            printf("%d %d\n",i,1);
        }
        return;
    }
    if (n==m) {
        for (int i=1;i<=n-1;i++) {
            printf("%d %d\n",1,i);
            printf("%d %d\n",n,i);
        }
        return;
    }
    if ((n>m)&&((n!=m*2)||(m%2==0))) {
        for (int i=1;i<=m;i++) {
            printf("%d %d\n",n,i);
        }
        solve(n-m,m);
        return;
    }
    if ((m>n)&&((m!=n*2)||(n%2==0))) {
        for (int i=1;i<=n;i++) {
            printf("%d %d\n",i,m);
        }
        solve(n,m-n);
        return;
    }
    if (n==m*2) {
        for (int i=1;i<=m;i++) {
            printf("%d %d\n",1,i);
            printf("%d %d\n",n,i);
        }
        for (int i=2;i<=m;i+=2) {
            printf("%d %d\n",m,i);
            printf("%d %d\n",m+1,i);
        }
        return;
    }
    if (m==n*2) {
        for (int i=1;i<=n;i++) {
            printf("%d %d\n",i,1);
            printf("%d %d\n",i,m);
        }
        for (int i=2;i<=n;i+=2) {
            printf("%d %d\n",i,n);
            printf("%d %d\n",i,n+1);
        }
        return;
    }
}
int main() {
    freopen("bishop.in","r",stdin);
    freopen("bishop.out","w",stdout);
    scanf("%d%d",&n,&m);
    //Does the problem provider play genshin impact very well?
    if ((n==m)||(n%2==0)&&(m%2==0)) {
        printf("%d\n",n+m-2);
    } else {
        printf("%d\n",n+m-1);
    }
    solve(n,m);
    return 0;
}
